"uniform vec4 gTransform[4];\n"
"uniform vec4 gWorldMatrix[3];\n"
"uniform vec4 gInvTransposedWorldMatrix[3];\n"
"uniform vec4 gMatrixPalette[36];\n"
"uniform vec4 gDiffuseColor;\n"
"uniform vec3 gAmbient;\n"
"uniform vec4 gLightPosX;\n"
"uniform vec4 gLightPosY;\n"
"uniform vec4 gLightPosZ;\n"
"uniform vec3 gLightColor0;\n"
"uniform vec3 gLightColor1;\n"
"uniform vec3 gLightColor2;\n"
"uniform vec3 gLightColor3;\n"
"attribute vec4 POSITION0;\n"
"attribute vec4 COLOR0;\n"
"attribute vec2 TEXCOORD0;\n"
"attribute vec3 NORMAL0;\n"
"attribute vec4 BLENDWEIGHT;\n"
"attribute vec4 BLENDINDICES;\n"
"varying vec4 v_color;\n"
"varying vec2 v_texcoord;\n"
"void main() {\n"
"  int index[4];\n"
"  index[0] = int(BLENDINDICES.x);\n"
"  index[1] = int(BLENDINDICES.y);\n"
"  index[2] = int(BLENDINDICES.z);\n"
"  index[3] = int(BLENDINDICES.w);\n"
"  float weight[4];\n"
"  weight[0] = BLENDWEIGHT.x;\n"
"  weight[1] = BLENDWEIGHT.y;\n"
"  weight[2] = BLENDWEIGHT.z;\n"
"  weight[3] = BLENDWEIGHT.w;\n"
"  vec4 tx = vec4(0);\n"
"  vec4 ty = vec4(0);\n"
"  vec4 tz = vec4(0);\n"
"  for(int i=0;i<4;++i){\n"
"    int idx = index[i]*3;\n"
"    float w = weight[i];\n"
"    tx += gMatrixPalette[idx  ] * w;\n"
"    ty += gMatrixPalette[idx+1] * w;\n"
"    tz += gMatrixPalette[idx+2] * w;\n"
"  }\n"
"  vec4 pos;\n" // 座標
"  pos.x = dot(tx, POSITION0);\n"
"  pos.y = dot(ty, POSITION0);\n"
"  pos.z = dot(tz, POSITION0);\n"
"  pos.w = 1.0;"
"  vec3 nrm;\n" // 法線
"  nrm.x = dot(tx.xyz, NORMAL0);\n"
"  nrm.y = dot(ty.xyz, NORMAL0);\n"
"  nrm.z = dot(tz.xyz, NORMAL0);\n"
"  vec4 final;\n"
"  final.x = dot( gTransform[ 0 ], pos );\n"
"  final.y = dot( gTransform[ 1 ], pos );\n"
"  final.z = dot( gTransform[ 2 ], pos );\n"
"  final.w = dot( gTransform[ 3 ], pos );\n"
"  final.z = 2.0 * final.z - final.w;\n"
"  gl_Position = final;\n"
"  vec3 wp;\n" //ワールド位置
"  wp.x = dot( gWorldMatrix[ 0 ], pos );\n"
"  wp.y = dot( gWorldMatrix[ 1 ], pos );\n"
"  wp.z = dot( gWorldMatrix[ 2 ], pos );\n"
"  vec3 wn;\n" //ワールド法線
"  wn.x = dot( gInvTransposedWorldMatrix[ 0 ].xyz, nrm );\n"
"  wn.y = dot( gInvTransposedWorldMatrix[ 1 ].xyz, nrm );\n"
"  wn.z = dot( gInvTransposedWorldMatrix[ 2 ].xyz, nrm );\n"
"  vec4 lvX, lvY, lvZ;\n"
"  lvX = gLightPosX - wp.xxxx;\n"
"  lvY = gLightPosY - wp.yyyy;\n"
"  lvZ = gLightPosZ - wp.zzzz;\n"
"  vec4 lvL;\n"
"  lvL = lvX * lvX;\n"
"  lvL += lvY * lvY;\n"
"  lvL += lvZ * lvZ;\n"
"  lvL += 0.00001;\n"
"  vec4 d = lvX * wn.xxxx;\n"
"  d += lvY * wn.yyyy;\n"
"  d += lvZ * wn.zzzz;\n"
"  d /= lvL;\n"
"  d = max( vec4( 0.0 ), d );\n"
"  vec3 c;\n"
"  c = gAmbient.xyz;\n"
"  c += gLightColor0 * d.x;\n"
"  c += gLightColor1 * d.y;\n"
"  c += gLightColor2 * d.z;\n"
"  c += gLightColor3 * d.w;\n"
"  v_color.xyz = c * COLOR0.zyx * gDiffuseColor.xyz;\n"
"  v_color.w = COLOR0.w * gDiffuseColor.w;\n"
"  v_texcoord = TEXCOORD0;\n"
"}"
